/**
 * 
 */
package lib.algo;

/**
 * @author <a href="www.sureinterview.com">SureInterview</a>
 */
public class FloodfillRecImpl<T extends Comparable<T>> extends FloodfillAbs<T> {
	/*
	 * http://en.wikipedia.org/wiki/Flood_fill#The_algorithm
	 */
	@Override
	protected void foolfill(int x, int y) {
		if (x < 0 || x >= width)
			return;
		if (y < 0 || y >= height)
			return;
		T curr = space[x][y];
		if (curr.compareTo(target) != 0)
			return;

		space[x][y] = replace;
		foolfill(x - 1, y);
		foolfill(x + 1, y);
		foolfill(x, y - 1);
		foolfill(x, y + 1);
	}
}
